package database

import (
	"gitee.com/sansaniot/ssiot-core/facade/runtime"

	"ssadmin/common/constant"
	"ssadmin/internal/admin/models"
)

// 仅创建、AutoMigrate会修改已存在表字段类型(-- 写好新增表的标签信息 --)
func Migrate() {
	db := runtime.Runtime.GetDbByKey("db")
	if db == nil {
		return
	}
	if !db.Migrator().HasTable(&models.SysConf{}) {
		_ = db.AutoMigrate(&models.SysConf{})
		initRows := make([]models.SysConf, 0)
		initRows = append(initRows, models.SysConf{
			Key:    constant.FileCleanThreshold,
			Value:  "10",
			Remark: "磁盘余量百分比，触发业务文件清理",
		})
		initRows = append(initRows, models.SysConf{
			Key:    constant.FileCleanType,
			Value:  "roll",
			Remark: "文件清理方式,roll:滚动,discard:丢弃",
		})
		db.Model(&initRows).Create(&initRows)
	}

}
